﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EnvDTE80;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using TeamReview.Services;
using TeamReview.Settings;

namespace TeamReview.UI
{
    /// <summary>
    /// Interaction logic for CreateWorkItemForm.xaml
    /// </summary>
    public partial class CreateWorkItemForm : Window
    {
        #region Variables

        private CodeSelectionModel _codeSelection;
        private readonly DTE2 shellDTE;
        private Project workItemSubmissionProject;
        private readonly SettingsReaderWriter settings =null;
        private TeamSetting teamSetting;

        #endregion
        public CreateWorkItemForm()
        {
            InitializeComponent();
            //settings = new SettingsReaderWriter();
        }
        public CreateWorkItemForm(DTE2 shell, CodeSelectionModel codeSelection)
        {
            InitializeComponent();
            //settings = new SettingsReaderWriter();
            //shellDTE = shell;
            _codeSelection = codeSelection;
            var resource = this.Resources["CreateWorkItemVM"] as CreateWorkItemViewModel;
            resource.SelectedRecord.CodeSnippet = _codeSelection.Snippet;
            if (String.IsNullOrEmpty(_codeSelection.CodeMember))
                resource.SelectedRecord.Title = String.Format("{0} {1}-{2}", _codeSelection.CodeFile, _codeSelection.StartLine, _codeSelection.EndLine);
            else
                resource.SelectedRecord.Title = String.Format("{0} {1}-{2}", _codeSelection.CodeMember, _codeSelection.StartLine, _codeSelection.EndLine);

            //RestoreWindow();
            // TODO TFSService.TeamProjectChanged += new TeamProjectChangeEventHandler(TFSService_TeamProjectChanged);

            //Binidng queries can kick off a number of threads to bind other
            //drop downs so we put it first in sequence for better percieved performance
            // TODO BindQueries();

            // TODO BindToolTips();
            // TODO BindTextBoxes();
        }


        private void RestoreWindow()
        {
            WindowSetting ws = settings.Get(this.Name);
            TeamProject project = new  TFSServiceAccess().GetTeamProject();
            teamSetting = settings.Get(project);

            if (teamSetting == null)
            {
                teamSetting = new TeamSetting();
                teamSetting.ArtifactUri = project.ArtifactUri.ToString();
            }

            if (ws == null)
                return;

            // TODO this.Position = FormStartPosition.Manual;
            Width = ws.Width;
            Height = ws.Height;
            // TODO Location = ws.WindowPoint;
            // TODO WindowState = ws.WindowState;
        }
        
    }
}
